package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.PlanDevelopment;
import cn.wolfcode.crm.query.PlanDevelopmentQueryObject;
import cn.wolfcode.crm.service.IPlanDevelopmentService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: crm
 * @description:
 * @author: Mr.chen
 * @create: 2018-07-07 22:06
 **/
@Controller
@RequestMapping("plandevelopment")
public class PlanDevelopmentController {

    @Autowired
    private IPlanDevelopmentService service;

    @RequestMapping("")
    @PermissionName("客户开发计划主页")
    @RequiresPermissions("plandevelopment:index")
    public String index() {
        return "plandevelopment/list";
    }

    @RequestMapping("list")
    @ResponseBody
    @RequiresPermissions("plandevelopment:list")
    @PermissionName("客户开发计划数据")
    public PageResult list(PlanDevelopmentQueryObject qo) {
        PageResult result = service.query(qo);
        return result;
    }

    @RequestMapping("save")
    @ResponseBody
    @RequiresPermissions("plandevelopment:save")
    @PermissionName("客户开发计划保存")
    public JsonResult save(PlanDevelopment entity) {
        JsonResult result = new JsonResult();
        try {
            service.save(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @ResponseBody
    @RequiresPermissions("plandevelopment:update")
    @PermissionName("客户开发计划更新")
    public JsonResult update(PlanDevelopment entity) {
        JsonResult result = new JsonResult();
        try {
            service.update(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("更新操作失败");
        }
        return result;
    }
}
